package ADT;
import static ADT.Values.*;
/**
 *
 * @author Martin
 */
public class PowerInW extends Scalar implements Power{
    private final double watt;
    
    @Override public boolean isValid() {return true;}
    @Override public boolean isZero() {return watt == 0;}
    
    public PowerInW(double watt){
        this.watt =  watt;
    } 
    
    @Override
    public Power inverse(){
        return new PowerInW(this.watt * -1);
    }
    
    @Override
    public double  getW(){
        return watt;
    }
    
    @Override
    public Power add(Power power){
       return valueOf(this.getW() + power.getW());
    }
   
    @Override
    public Power sub(Power power){
        return valueOf(this.getW() - power.getW());
    }
    
    @Override
    public Power div(double factor){
        return valueOf(this.watt / factor);
    }
    
    @Override
    public  Power mul(double factor){
        return valueOf(this.watt * factor);
    }
    
    @Override
    public double div(Power power){
        return this.watt / power.getW();
    }
    
    @Override public Force div(Speed speed){return forceInN(watt / speed.getMS());}
    
    public String toString(Power power){
        return String.format("%.2d Watt");
    }
    
    @Override
    public int compareTo(Power power){
        return Double.compare(this.watt, power.getW());
    }
    
    @Override
    public boolean equals(Object o){
        if(this == o) return true;
        if(!(o instanceof PowerInW)) return false;
        return this.compareTo((PowerInW)o) == 0;
    }
    
    
    public static Power valueOf(double watt){
        return new PowerInW(watt);
    }
    
    @Override
    public int hashCode(){
        return hashDouble(watt);
    }
}